﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        { }
             class Vehicle
        {
            protected int wheels;
            protected float weight;
            public void SetVehicle(int wheels, float weight)
            {
                this.wheels = wheels;
                this.weight = weight;
            }
            public virtual void GetVehicle()
            {
                MessageBox.Show($"车轮数：{wheels}\n车重：{weight}");
            }
        }

        class Truck : Vehicle
        {
            private float maxLoad;
            private float oilPerKm;
            public void SetVehicle(int wheels, float weight, float maxLoad, float oilPerKm)
            {
                this.wheels = wheels;
                this.weight = weight;
                this.maxLoad = maxLoad;
                this.oilPerKm = oilPerKm;
            }
            public bool Overload(float load) => load > maxLoad;
            public float OilConsumption(float runKm) => runKm * oilPerKm;
            public new void GetVehicle()
            {
                MessageBox.Show($"车轮数：{wheels}\n车重：{weight}\n载重限量：{maxLoad}\n每公里油耗：{oilPerKm}");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int wheels = int.Parse(textBox1.Text);
            float weight = float.Parse(textBox2.Text);
            float maxLoad = float.Parse(textBox3.Text);
            float oilPerKm = float.Parse(textBox4.Text);
            float runKm = float.Parse(textBox5.Text);
            float load = float.Parse(textBox6.Text);

            Truck t = new Truck();
            t.SetVehicle(wheels, weight, maxLoad, oilPerKm);

            if (t.Overload(load))
            {
                MessageBox.Show("对不起！卡车已超载，请卸下一些货物。");
                textBox6.Focus();
            }
            else
            {
                MessageBox.Show($"卡车正在行驶中...\n现已耗油：{t.OilConsumption(runKm)}升");
                t.GetVehicle();
            }
        }
    }
}
